
#ifndef __BSP_MOTOR_CONTROL_H
#define __BSP_MOTOR_CONTROL_H

#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "usart.h"
#include <stdio.h>
#include <string.h>
#include "tim.h"
#include <stdint.h>
#include <stdlib.h>
#include "bsp_uni_remote.h"
#include "sbus_ht10a.h"
#include "lidar_ld06.h"

// 或者设置死区，避免电机无法启动
#define MIN_PWM 56   // 电机启动所需的最小PWM
#define MAX_PWM 100

// 定时器配置结构体
typedef struct {
    TIM_HandleTypeDef *tim;
    uint32_t channel;
} TIM_Config_t;

// 电机控制结构体 前后转分别用两个不同的TIM
typedef struct {
    TIM_HandleTypeDef* forward_tim;
    uint32_t forward_ch;
    TIM_HandleTypeDef* backward_tim;  
    uint32_t backward_ch;
} Motor_TIM_HandleTypeDef;

// 电机配置结构体
typedef struct {
    Motor_TIM_HandleTypeDef *motor;
    TIM_HandleTypeDef *forward_tim;
    uint32_t forward_ch;
    TIM_HandleTypeDef *backward_tim;
    uint32_t backward_ch;
} Motor_Config_t;


// 函数声明
void BSP_MotorControl_Init(void);
void BSP_MotorControl_Loop(SBUS_HandleTypeDef* hsbus, LiDARFrameTypeDef* ld06_frame);// 传入的标准RBUS句柄

// 全局电机对象声明
extern Motor_TIM_HandleTypeDef motor_left_front, motor_right_front, motor_left_back, motor_right_back;

#endif